using UnityEngine;
using UnityEngine.UI;
using System.Collections;

[AddComponentMenu("TagMachine/UI/Game/Pause Menu")]
public class UIPauseMenu : MonoBehaviour
{
	public GameObject ButtonsContainer 	= null;
	public Button ReplayButton 			= null;
	public Button MainMenuButton 		= null;
	public string MainMenu 				= "MainMenu";

	void Awake()
	{
		ButtonsContainer.SetActive( false );

		if ( GameModeClassic.Exists )
		{
			ReplayButton.onClick.AddListener( GameModeClassic.Instance.Restart );
		}
		MainMenuButton.onClick.AddListener( () => Application.LoadLevel( MainMenu ) );
	}

	// Update is called once per frame
	void Update ()
	{
		if ( Input.GetButton( "Pause" ) )
		{
			GameModeClassic.Instance.TogglePause();
		}

		if ( GameModeClassic.Instance.IsGameEnded ||
			GameModeClassic.Instance.IsPaused )
		{
			if ( !ButtonsContainer.activeInHierarchy )
			{
				ButtonsContainer.SetActive( true );
			}
		}
		else
		{
			if ( ButtonsContainer.activeInHierarchy )
			{
				ButtonsContainer.SetActive( false );
			}
		}
	}
}
